<div class="dialog-div">
<table width="100%" border="1" cellspacing="0" cellpadding="0">
	<tr>
	  <th colspan="4" align="left">采购产品</th>
	  </tr>
	<tr>
	  <th>产品名称</th>
	  <td><input name='p_name' type='text' id="p_name"></td>
	  <th>产品代码</th>
	  <td><input name='p_code' type='text' id='p_code' /></td>
	</tr>
	<tr>
	  <th>产品规格</th><td><input name='p_specification' type='text' id='p_specification'></td>
	  <th>产品分类</th>
	  <td>
	    <select name="p_cat_id" id="p_cat_id">
        	<option value="0" selected="selected">请选择</option>
	        {$product_cat_option}
      </select></td>
	</tr>
	<tr>
	  <th>进货价</th>
	  <td><input name='p_purchase_price' type='text' id="p_purchase_price"  /></td>
	  <th>进货数量</th>
	  <td><input name='p_number' type='text' id="p_number"  /></td>
	</tr>
    <tr>
      <th>供应商</th>
      <td>
        <select name="p_supplier_id" id="p_supplier_id">
          <option selected="selected">请选择</option>
          <foreach name="list_supplier" item="supplier">
          <option value="{$supplier[id]}">{$supplier[name]}</option>
          </foreach>
        </select>
        <a href="#">添加供应商</a></td>
	  <th>存放仓库</th>
	  <td><select name="p_storage_id" id="p_storage_id">
	    <option value="0" selected="selected">请选择</option>
	    {$storage_option}
      </select></td>
	</tr>
    <tr>
	  <td colspan="4" align="center"><input type="button" name="button" id="button" value="登记到此单" onclick="dengji();" /></td>
	  </tr>
      </table>
<form method='post'  id="form_{$_REQUEST[_URL_][2]}" action="{:U($_REQUEST[_URL_][2])}" onsubmit="return check_submit();">
<input name="act" type="hidden" id="act" value="todo">
   <table width="100%" border="1" cellspacing="0" cellpadding="0">   
	<tr>
	  <th colspan="4" align="left">采购单详细信息
	    <input type="submit" name="button2" id="button2" value="提交采购入库记录" /></th>
	  </tr>
<tr>
	  <th>采购单号</th>
	  <td><input name='procure[procure_num]' type='text'  id="procure_num" value="{:procure_number()}" /></td>
	  <th>采购员</th>
	  <td>
	    <select name="procure[buyer_id]" id="procure[buyer_id]">
        <foreach name="list_user" item="user">
	      <option value="{$user[id]}">{$user['nickname']}</option>
	    </foreach>
        </select></td>
	  </tr>
      <tr>
	  <th>采购日期</th>
	  <td><input name='procure[buy_date]' type='text' class="date" value="<php>echo date('Y-m-d');</php>" /></td>
	  <th>入库日期</th>
	  <td><input name='procure[warehouse_date]' type='text'  class="date" value="<php>echo date('Y-m-d');</php>"/></td>
	  </tr>
      <tr>
	  <th>总金额</th>
	  <td><input name='procure[total_amount]' type='text'  id="total_amount" value="0" /></td>
	  <th>付款银行帐号</th>
	  <td><select name='procure[bank_account]' id="bank_account">
	    <option selected="selected" value="">请选择</option>
        <foreach name="list_bank_account" item="bank_account">
        <option value="{$bank_account[account]}">{$bank_account[bank]}({$bank_account[account]})</option>
        </foreach>
	  </select></td>
	  </tr>
<tr>
  <td colspan="4"><table id="table_procure" width="100%" border="1" cellspacing="0" cellpadding="0">
    <tr>
      <th>产品名称</th>
      <th>产品代码</th>
      <th>产品规格</th>
      <th>产品数量</th>
      <th>产品单价</th>
    </tr>
  </table></td>
</tr>
</table>
</form>
</div>
<script language="javascript">
$('.date').datepicker();
//登记到此单
var i=1;
function dengji(){
	var name=$("#p_name").val();
	var code=$("#p_code").val();
	var supplier_id=$("#p_supplier_id").val();
	var cat_id=$("#p_cat_id").val();
	var storage_id=$("#p_storage_id").val();
	var specification=$("#p_specification").val();
	var number=$("#p_number").val();
	var purchase_price=$("#p_purchase_price").val();
	var html='<tr><td><input name="list_procure_product['+i+'][name]" type="text" value="'+name+'" /></td>';
    html+='<td><input name="list_procure_product['+i+'][code]" type="text" value="'+code+'"/><input type="hidden" name="list_procure_product['+i+'][supplier_id]" value="'+supplier_id+'" /><input type="hidden" name="list_procure_product['+i+'][cat_id]" value="'+cat_id+'" /><input type="hidden" name="list_procure_product['+i+'][storage_id]" value="'+storage_id+'" /></td>';
    html+='<td><input name="list_procure_product['+i+'][specification]" type="text" value="'+specification+'" /></td>';
    html+='<td><input name="list_procure_product['+i+'][number]" type="text" value="'+number+'" /></td>';
    html+='<td><input name="list_procure_product['+i+'][purchase_price]" type="text" value="'+purchase_price+'" /></td></tr>';
	i++;
	$("#table_procure").append(html);
	//加入总金额
	var total_amount=$("#total_amount").val();
	$("#total_amount").val(Number(total_amount)+Number(purchase_price)*Number(number));
}
//检查表单数据完整性
function check_submit(){
	
}
</script>